package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiTradeApplicationFile;
import com.minimalist.common.entity.lindi.vo.tradeapplicationfile.LindiTradeApplicationFileQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

/**
 * 林地指标交易平台_交易申请相关文件 映射层。
 *
 * @author 11987
 * @since 2025-04-27
 */
public interface LindiTradeApplicationFileMapper extends BaseMapper<LindiTradeApplicationFile>{

    /**
     * 根据交易申请相关文件ID查询交易申请相关文件
     *
     * @param tradeApplicationFileId 交易申请相关文件ID
     * @return 交易申请相关文件
     */
    default LindiTradeApplicationFile selectTradeApplicationFileByTradeApplicationFileId(Long tradeApplicationFileId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationFile::getTradeApplicationFileId, tradeApplicationFileId)
        );
    }

    /**
     * 根据查询条件分页查询交易申请相关文件列表
     *
     * @param queryVO 查询条件
     * @return 交易申请相关文件分页列表
     */
    default Page<LindiTradeApplicationFile> selectPageTradeApplicationFileList(LindiTradeApplicationFileQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .eq(LindiTradeApplicationFile::getFileType, queryVO.getFileType())
                        .eq(LindiTradeApplicationFile::getTradeApplicationId, queryVO.getTradeApplicationId())
                        .orderBy(LindiTradeApplicationFile::getCreateTime, false));
    }

    /**
     * 根据交易申请ID查询交易申请相关文件列表
     *
     * @param tradeApplicationId 交易申请ID
     * @return 交易申请相关文件列表
     */
    default List<LindiTradeApplicationFile> selectTradeApplicationFilesByTradeApplicationFileId(Long tradeApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationFile::getTradeApplicationId, tradeApplicationId)
                .orderBy(LindiTradeApplicationFile::getCreateTime, false)
        );
    }

    /**
     * 获取交易申请相关文件列表
     *
     * @param tradeApplicationId 交易申请ID
     * @return 交易申请相关文件列表
     */
    default List<LindiTradeApplicationFile> selectTradeApplicationFilesByTradeApplicationId(
            Long tradeApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationFile::getTradeApplicationId, tradeApplicationId)
        );
    }

    /**
     * 删除交易申请相关文件
     *
     * @param tradeApplicationId 交易申请ID
     * @return 删除数量
     */
    default int deleteTradeApplicationFilesByTradeApplicationId(Long tradeApplicationId){
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationFile::getTradeApplicationId, tradeApplicationId)
        );
    }
}
